﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace genericsvsobjects
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Testing Objects vs. Generics");

            Console.WriteLine("Creating DataClass Instances");
            List<DataClass> _genericList = new List<DataClass>();
            DataClassCollection _objectList = new DataClassCollection();
            for (int i = 0; i < 5000; i++)
            {
                DataClass @new = new DataClass();
                _genericList.Add(@new);
                _objectList.Add(@new);
            }

            Console.WriteLine("Iterating Over Generics");
            Stopwatch genericTimer = new Stopwatch();
            genericTimer.Start();
            foreach (var dataClass in _genericList)
            {
                string s = dataClass.InstanceName;
            }
            genericTimer.Stop();
            Console.WriteLine(string.Format("Generics Time: {0} Ticks", genericTimer.ElapsedTicks));

            Console.WriteLine("Iterating Over ArrayList");
            Stopwatch objectTimer = new Stopwatch();
            objectTimer.Start();
            foreach (var o in _objectList)
            {
                DataClass dc = (DataClass) o;
                string s = dc.InstanceName;
            }
            objectTimer.Stop();
            Console.WriteLine(string.Format("Objects Time: {0} Ticks", objectTimer.ElapsedTicks));

            string winner = 
                genericTimer.ElapsedTicks > objectTimer.ElapsedTicks ?
                    "Objects" : "Generics";
            Console.WriteLine(string.Format("{0} Wins!", winner));
        }
    }
}
